# class Test:
#     def __enter__(self):
#         print("__enter__")
#         return "hello python"

#     def __exit__(self, type, value, trace):
#         print("__exit__")
#         pass

# def get_test():
#     return Test()

# with get_test() as test:
#     print(test)


class Test:
    def __enter__(self):
        print("__enter__")
        return "hello python"

    def __exit__(self, type, value, trace):
        print("type", type)
        print("value", value)
        print("trace", trace)
        print("__exit__")
        return True


def get_test():
    return Test()


with get_test() as test:
    print(test)
    1 / 0

# 多个with的使用

# with A() as a, with B() as b:
#     body


# with A() as a:
#     with B() as b:
#         body

# 文件自动关闭

with open() as f:
    pass


